import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import {withRouter} from 'react-router'
import mobiscroll from "mobiscroll"
import ListView from './ListView'

@connect(
	state => {
		return {
		}
	}
)
@withRouter
export default class List extends Component {

  static propTypes = {

  }

  constructor(props){
    super(props);
    this.state = {
      requestOptions : {
        url:'/api/list'
      },
      useFilter: false,
      // data:[
      //   {id:1,name:'saa'},
      //   {id:2,name:'adfs'},
      //   {id:3,name:'dsfdas'},
      //   {id:4,name:'sdfdsf'},
      //   {id:5,name:'sdf'},
      //   {id:6,name:'d'},
      //   {id:7,name:'df'},
      //   {id:8,name:'adf'},
      //   {id:9,name:'sdf'},
      //   {id:10,name:'erq'},
      //   {id:11,name:'saa'},
      //   {id:12,name:'adfs'},
      //   {id:13,name:'dsfdas'},
      //   {id:14,name:'sdfdsf'},
      //   {id:15,name:'sdf'},
      //   {id:16,name:'d'},
      //   {id:17,name:'df'},
      //   {id:18,name:'adf'},
      //   {id:19,name:'sdf'},
      //   {id:20,name:'erq'},
        
      //   ]
      // data: [{id:5},{id:0},{id:1},{id:1},{id:1},{id:0},{id:1},{id:1},{id:0},{id:1},{id:0},{id:1},{id:1},{id:1},{id:1}],
    }

 //   this.renderRow = this.renderRow.bind(this);
    //this.onConfirm = this.onConfirm.bind(this);
  //  this.handlePullAction = this.handlePullAction.bind(this);
  }




	render() {
		return (
			<div>
        <button onClick={this.onclick}>button</button>
       <ListView
            ref="list"
            ptrClass="list-with-search"
            requestOptions={this.state.requestOptions}
            renderRow={this.renderRow}
           // handlePullAction={this.handlePullAction}
          />
       {/// <ListView
          //  ptrClass="list-with-search"
          //  offline
          //  iScroll={false}
          //  data={this.state.data}
          //  onFilter={this.state.onFilter}
          //  requestOptions={this.state.requestOptions}
          //  renderRow={this.renderRow}
          //  handlePullAction={this.handlePullAction}
          // />
        }
			</div>
		);
	}

  onclick = () => {
    console.log('sdfsf')
  }
  
  handlePullAction = (downOrUp, data) => {
    // do some async code here
    debugger
    if(downOrUp == "up"){ //next page
      return [...data,...this.state.data]
    }else{  // refresh
      return this.state.data
    }
  }
  renderRow = (item, index) => {
    return (
     <div >
       <div className="mbsc-ic mbsc-ic-home" key={index}> 
         {item.name}
       </div>
       <p>{item.id}</p>
     </div>
    );
  }

  onConfirm = (e) => {
    const value = e.currentTarget.value
    console.log(value);
    var filter;
    if(value && value != ''){
      filter = function(item){
        return item.id == value;
      }.bind(this)
    }
    this.setState({onFilter: filter});
  }

}
